home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d21 / dvmam11.arc / DV_TEST.C < prev    next >
C/C++ Source or Header  |  1990-11-24  |  5KB  |  194 lines

  1. #include <dvmam.h>
  2. #include <conio.h>
  3. #include <dos.h>
  4.  
  5. unsigned long bytes_available(void);
  6. unsigned long bytes_total(void);
  7.  
  8. void main(void)
  9. {
  10.  int    b[10];
  11.  char   buf[14],buf2[14];
  12.  int    i;
  13.  int    result=0;
  14.  char * set[10]= {"1","2","3","4","5","6","7","8","9","0"};
  15.  int    x;
  16.  
  17.  clrscr();
  18.  memory_setup(5120);
  19.  
  20.  printf("CPU type: 80%d\n",cpu_type());
  21.  if (emm_installed()) printf("Expanded memory available.\n");
  22.  if (kbytes_ext()>0 && cpu_type()==286 || cpu_type()==386)
  23.     printf("Extended memory available.\n");
  24.  
  25.  for (x=1; x<5; x++)
  26.  {
  27.   printf("\n");
  28.  
  29. /**************************************/
  30. /* print the memory type we are using */
  31. /**************************************/
  32.  
  33.   switch (x)
  34.   {
  35.    case 1: printf("Using conventional memory\n");
  36.            set_memory_usage(USE_CONV);
  37.            break;
  38.    case 2: printf("Using expanded memory\n");
  39.            set_memory_usage(USE_EMS);
  40.            break;
  41.    case 3: printf("Using extended memory\n");
  42.            set_memory_usage(USE_EXT);
  43.            break;
  44.    case 4: printf("All memory types in use.\n");
  45.            set_memory_usage(USE_CONV+USE_EMS+USE_EXT);
  46.            break;
  47.   }
  48.  
  49. /********************************************************/
  50. /* Show the amount of memory available and total memory */
  51. /********************************************************/
  52.  
  53.   printf("Memory available: %lu of %lu bytes\n",bytes_available(),bytes_total());
  54.  
  55.   printf("Allocating 10 5k blocks: ");
  56.  
  57. /*************************/
  58. /* Allocate 10 5k blocks */
  59. /*************************/
  60.  
  61.   result=0;
  62.   for (i=0; i<10; i++) if ((b[i]=alloc_mem(5120))==-1) result=1;
  63.  
  64.   if (result) printf("Failed!\n"); else printf("Ok\n");
  65.  
  66. /*****************/
  67. /* Setup strings */
  68. /*****************/
  69.  
  70.   i=0;
  71.   result=0;
  72.   do
  73.   {
  74.    i++;
  75.    strcpy(buf2,"String test ");
  76.    strcat(buf2,set[i-1]);
  77.    movedata(FP_SEG( (char far *) buf2),FP_OFF( (char far *) buf2),
  78.             FP_SEG(dvmam_dta),FP_OFF(dvmam_dta),13);
  79.    result=save_memory(b[i-1]);
  80.   }
  81.   while (i<10 && !result);
  82.  
  83.   if (!result && i==10) printf("Initial strings established\n"); else
  84.                         printf("Error saving initial strings\n");
  85.  
  86. /**********************/
  87. /* Do the string test */
  88. /**********************/
  89.  
  90.   i=0;
  91.   result=0;
  92.   do
  93.   {
  94.    i++;
  95.    strcpy(buf,"String test ");
  96.    strcat(buf,set[i-1]);
  97.    result=load_memory(b[i-1]);
  98.    movedata(FP_SEG(dvmam_dta),FP_OFF(dvmam_dta),
  99.             FP_SEG( (char far *) buf2),FP_OFF( (char far *) buf2),13);
  100.    if (result==0) result=strcmp(buf,buf2);
  101.   }
  102.   while (i<10 && !result);
  103.  
  104.   if (!result && i==10) printf("String test successful\n"); else
  105.                         printf("String test failed\n");
  106.  
  107. /*************************/
  108. /* Deallocate all memory */
  109. /*************************/
  110.  
  111.   printf("Deallocating memory: ");
  112.  
  113.   for (i=0; i<10; i++) if ((result=dealloc_mem(b[i]))==-1) i=10;
  114.  
  115.   if (result) printf("Failed\n"); else printf("Ok\n");
  116.  }
  117.  
  118.  printf("\nTesting across memory types: ");
  119.  
  120. /**************************************************/
  121. /* Set memory with all memory types going at once */
  122. /**************************************************/
  123.  
  124.  set_memory_usage(USE_CONV);
  125.  b[0]=alloc_mem(5120);
  126.  b[1]=alloc_mem(5120);
  127.  
  128.  set_memory_usage(USE_EXT);
  129.  b[2]=alloc_mem(5120);
  130.  b[3]=alloc_mem(5120);
  131.  
  132.  set_memory_usage(USE_EMS);
  133.  b[4]=alloc_mem(5120);
  134.  b[5]=alloc_mem(5120);
  135.  
  136.  result=0;
  137.  for (i=0; i<6; i++) if (b[i]==-1) result=1;
  138.  
  139.  if (result) printf("Failed\n"); else printf("Ok\n");
  140.  
  141. /*****************/
  142. /* Setup strings */
  143. /*****************/
  144.  
  145.  i=0;
  146.  result=0;
  147.  do
  148.  {
  149.   i++;
  150.    strcpy(buf2,"String test ");
  151.    strcat(buf2,set[i-1]);
  152.    movedata(FP_SEG( (char far *) buf2),FP_OFF( (char far *) buf2),
  153.             FP_SEG(dvmam_dta),FP_OFF(dvmam_dta),13);
  154.   result=save_memory(b[i-1]);
  155.  }
  156.  while (i<6 && !result);
  157.  
  158.  if (!result && i==6) printf("Initial strings established\n"); else
  159.                       printf("Error saving initial strings\n");
  160.  
  161. /**********************/
  162. /* Do the string test */
  163. /**********************/
  164.  
  165.  i=0;
  166.  result=0;
  167.  do
  168.  {
  169.   i++;
  170.   strcpy(buf,"String test ");
  171.   strcat(buf,set[i-1]);
  172.   result=load_memory(b[i-1]);
  173.   movedata(FP_SEG(dvmam_dta),FP_OFF(dvmam_dta),
  174.            FP_SEG( (char far *) buf2),FP_OFF( (char far *) buf2),13);
  175.   if (!result) result=strcmp(buf,buf2);
  176.  }
  177.  while (i<6 && !result);
  178.  
  179.  if (!result && i==6) printf("String test successful\n"); else
  180.                       printf("String test failed\n");
  181.  
  182.  result=0;
  183.  printf("Deallocating memory: ");
  184.  
  185. /*************************/
  186. /* Deallocate the memory */
  187. /*************************/
  188.  
  189.  for (i=0; i<6; i++) if ((result=dealloc_mem(b[i]))==-1) i=10;
  190.  if (result) printf("Failed\n"); else printf("Ok\n");
  191.  
  192.  memory_shutdown();
  193.  
  194. }